package com.xul.crowd.controller;

import com.xul.crowd.service.OrderService;
import com.xul.crowd.util.ResultEntity;
import com.xul.entity.vo.AddressVO;
import com.xul.entity.vo.OrderProjectVO;
import com.xul.entity.vo.OrderVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * @author xul
 * @create 2021-08-01 17:07
 */
@RestController
public class OrderProviderController {

    @Autowired
    private OrderService orderService;

    /**
     * 根据returnId查询回报信息 给order远程调用
     *
     * @param projectId
     * @param returnId
     * @return
     */
    @RequestMapping("get/order/project/remote")
    public ResultEntity<OrderProjectVO> getOrderProjectRemote(@RequestParam("projectId") Integer projectId,
                                                              @RequestParam("returnId") Integer returnId) {
        try {
            OrderProjectVO orderProjectVO = orderService.getOrderProjectVO(projectId, returnId);
            return ResultEntity.successWithData(orderProjectVO);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultEntity.failed(e.getMessage());
        }
    }

    /**
     * 查询目前的收获地址数据
     *
     * @param memberId
     * @return
     */
    @RequestMapping("get/address/vo/remote")
    public ResultEntity<List<AddressVO>> getAddressVORemote(@RequestParam("memberId") Integer memberId) {
        try {
            List<AddressVO> addressVOList = orderService.getAddressVOList(memberId);
            return ResultEntity.successWithData(addressVOList);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultEntity.failed(e.getMessage());
        }
    }

    /**
     * 保存会员地址信息
     *
     * @param addressVO
     * @return
     */
    @RequestMapping("save/address/remote")
    public ResultEntity<String> saveAddressRemote(@RequestBody AddressVO addressVO) {

        try {
            orderService.saveAddress(addressVO);
            return ResultEntity.successWithData();
        } catch (Exception e) {
            e.printStackTrace();
            return ResultEntity.failed(e.getMessage());
        }

    }

    /**
     * 保存订单所有信息
     *
     * @param orderVO
     * @return
     */
    @RequestMapping("save/order/remote")
    public ResultEntity<String> saveOrderRemote(@RequestBody OrderVO orderVO) {
        try {
            orderService.saveOrder(orderVO);
            return ResultEntity.successWithData();
        } catch (Exception e) {
            e.printStackTrace();
            return ResultEntity.failed(e.getMessage());
        }
    }


}
